#include "chatroom.h"
#include "stdShared.h"
#include <cstring>
ChatRoom::ChatRoom(const StdTcpSocketPtr &clientInfo):m_clientSock(clientInfo)
{

}

ChatRoom::~ChatRoom()
{
}

void ChatRoom::ChatMenu()
{   
    std::cout<<"1.添加好友"<<std::endl;
    std::cout<<"2.删除好友"<<std::endl;
    std::cout<<"3.好友聊天"<<std::endl;
    std::cout<<"4.黑名单"<<std::endl;

    std::cout<<"5.创建群聊"<<std::endl;
    std::cout<<"6.退出群聊"<<std::endl;
    std::cout<<"7.加入群聊"<<std::endl;
    std::cout<<"8.邀请进群"<<std::endl;
    std::cout<<"9.群聊聊天"<<std::endl;
}

void ChatRoom::ChatEnter()
{
    ChatMenu();

    int choice = 0;
    cin >>choice;

    choice += m_offset;;

    switch (choice)
    {
    case ADDFRIEND:
        addFriend();
        break;
    case DELFRIEND:
        delFriend();
        break;
    case FRIENDCHAT:
        chatFriend();
        break;
    default:
        break;
    }
    

}

void ChatRoom::addFriend()
{
    string addName;
    cout<<"请输入添加联系人的用户名:"<<endl;
    cin >> addName;
    Msg msg;
    memset(&msg,0,sizeof(msg));

    msg.type = ADDFRIEND;
    strncpy(msg.toName,addName.c_str(),sizeof(msg.toName) - 1);
    m_clientSock->sendMessage((const void *)&msg, sizeof(msg));
    

}

void ChatRoom::delFriend()
{
    cout<<"delFriend"<<endl;
    string delName;
    cout<<"请输入删除联系人的用户名"<<endl;
    cin>>delName;

    Msg msg;
    memset(&msg,0,sizeof(msg));

    msg.type = DELFRIEND;
    strncpy(msg.toName,delName.c_str(),sizeof(msg.toName) - 1);
    m_clientSock->sendMessage((const void *)&msg, sizeof(msg));
}

void ChatRoom::chatFriend()
{
    string chatName;
    cout<<"请输入要聊天的好友用户名"<<endl;
    cin >> chatName;

    string chatContent;
    cout<<"请输入要聊天的内容"<<endl;
    cin >> chatContent;
} 
